package com.yang.order.dao;

import com.yang.springcloud.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.HashMap;
import java.util.Map;

@Repository
public class OrderImp implements OrderDao {
    @Autowired
    DataSource dataSource;

    Connection conn;
    PreparedStatement pstmt;


    @Override
    public Map<String, Object> addOrder(Order o) {
        int i;
        try {
            conn = dataSource.getConnection();
            pstmt = conn.prepareStatement("insert into student (order_user_id,order_user_name,good_list,total_amount,order_state) values(?,?,?,?,?)");
            pstmt.setInt(1, o.getOrderUserId());
            pstmt.setString(2, o.getOrderUserName());
            pstmt.setString(3, o.getGoodList());
            pstmt.setInt(4, o.getTotalAmount());
            pstmt.setInt(5,o.getOrderState());
            i = pstmt.executeUpdate();
            System.out.println(i);

            pstmt.close();
            conn.close();

        }catch (Exception e){
            e.printStackTrace();
        }

        Map<String, Object> msg = new HashMap<String, Object>();
        msg.put("massage", "插入成功");
        msg.put("code", 200);
        return msg;
    }
}
